extends AnimatedSprite2D
class_name MushroomAnimator

# 内部函数
var is_on_seat: bool = false
var can_drag: bool = true

enum mushroom_animator{
	Waiting,
	Seating,
	Falling,
	Oncontrol,
	Walking,
}

var current_animate_stat: int = mushroom_animator.Waiting

# 初始化
func _ready():
	add_to_group("mushroom")
	print(current_animate_stat)

func _process(delta: float) -> void:
	mushroom_animator_manage()

# 状态判断
# 根据状态执行不同的函数
func mushroom_animator_manage():
	match current_animate_stat:
		mushroom_animator.Waiting:
			_on_mushroom_animator_waiting()
		mushroom_animator.Falling:
			_on_mushroom_animator_falling()
		mushroom_animator.Seating:
			_on_mushroom_animator_seating()
		mushroom_animator.Oncontrol:
			_on_mushroom_animator_oncontrol()
		mushroom_animator.Walking:
			_on_mushroom_animator_walking()
	
# 当等待中时，向管理器发起排队申请
func _on_mushroom_animator_waiting():
	return


# 当处于被控制状态中，向管理器发起退出申请
func _on_mushroom_animator_oncontrol():
	play("drag")
	return

func _on_mushroom_animator_falling():
	play("fall")
	
# 当处于已分配座位时，向座位发出信号
func _on_mushroom_animator_walking():
	play("walk")
	
# 当已经坐好
func _on_mushroom_animator_seating():
	return

# 状态转移方法
func set_mushroom_animator_waiting():
	current_animate_stat = mushroom_animator.Waiting

func set_mushroom_animator_seating():
	current_animate_stat = mushroom_animator.Seating

func set_mushroom_animator_oncontrol():
	current_animate_stat = mushroom_animator.Oncontrol

func set_mushroom_animator_falling():
	current_animate_stat = mushroom_animator.Falling

func set_mushroom_animator_walking():
	current_animate_stat = mushroom_animator.Walking
